{% for cat in page.category %}
  {% if cat == 'needs-review' %}
    <div class="col-lg-12 row">
      {% alert info %}
This document has been marked `needs-review`. The following information may be outdated or may no longer apply to the latest Marlin.
      {% endalert %}
    </div>
  {% endif %}
{% endfor %}

<div class="col-lg-12 row meta" id="gcode-header">
  <p class="text-right pull-right visible-lg-block hidden-print small custom-pt25">
    {% assign authors = gcode.author | append: ',' | append: gcode.contrib | replace: " ","" | split: ',' %}
    {% if authors %}
      {% for author in authors %}
        <a href="//github.com/{{ author }}" data-toggle="tooltip" data-placement="bottom" title="Visit {{ author }}'s profile on Github">{% avatar user=author size=30 %}</a>
      {% endfor %}
    {% endif %}
  </p>

  <h1>{{ gcode.codes | codes_desc }} - {{ gcode.title }}</h1>

  {% if gcode.experimental %}
    <span class="label label-warning"><span data-toggle="tooltip" data-placement="bottom" title="Experimental feature"><i class="fa fa-flask" aria-hidden="true"></i></span></span>
  {% endif %}

  {% if gcode.since %}
    <span class="label label-success"><span data-toggle="tooltip" data-placement="bottom" title="Available since"><i class="fa fa-code" aria-hidden="true"></i>
    {{ gcode.since }}</span></span>
  {% endif %}

  {% if gcode.group %}
    <span class="label label-default"><i class="fa fa-tags" aria-hidden="true"></i>
    {{ gcode.group }}</span>
  {% endif %}

  {% if gcode.brief %}
    <span class="label label-primary"><i class="fa fa-pencil-square" aria-hidden="true"></i> {{gcode.brief}}</span>
  {% endif %}

  {% if gcode.requires %}
    {% assign list = (gcode.requires | split: ',') %}
    {% for item in list %}
      <span class="label label-requires"><code>{{item}}</code></span>
    {% endfor %}
  {% endif %}
</div>

{% if gcode.related %}
  <div class="col-lg-12 row related"><h5>
    Related codes: {% for item in gcode.related %}<a href="/docs/gcode/{{ item | linkify }}.html"><code>{{item}}</code></a> {% endfor %}
  </h5></div>
{% endif %}

<div class="col-lg-12 row long">
  <h3>Description</h3>
  {% if page.content %}
    {{ page.content | markdownify }}
  {% endif %}
</div>

{% if gcode.notes %}
  <div class="col-lg-12 row notes">
    <h3>Notes</h3>
      {% for line in gcode.notes %}
        {{ line | markdownify }}
      {% endfor %}
  </div>
{% endif %}

{% if gcode.devnotes %}
  <div class="col-lg-12 row devnotes">
    <h3>Developer Notes</h3>
      {% for line in gcode.devnotes %}
        {{ line | markdownify }}
      {% endfor %}
  </div>
{% endif %}

{% if gcode.pagetype != 'toc' %}
<div class="col-lg-12 row usage" id="usage-{{ gcode.tag }}">
  <h3>Usage</h3>
  <code>{{ gcode.codes[0] }}
    {% if gcode.parameters %}
      {% assign list = ('' | split: '|') %}
      {% for parm in gcode.parameters %}
        {% if parm.tag %}
          {% assign list = list | push: parm %}
        {% endif %}
      {% endfor %}

      {% if list.size > 0 %}
        {% assign list = (list | sort: 'tag') %}
        {% for parm in list %}
          <span data-toggle="tooltip" data-placement="top" data-original-title="{{ parm.description | markdownify | strip_html }}">
            {% if parm.optional %}&#x5B;{% endif %}<!--
            -->{{ parm.tag }}<!--
            -->{% if parm.values.size > 0 %}<!--
              -->{% if parm.values.size == 1 %}<!--
                -->{% assign pv = parm.values[0] %}<!--
                -->{% if pv.optional %}&#x5B;{% else %}&lt;{% endif %}<!--
                -->{% if pv.tag %}<!--
                  -->{{ pv.tag }}<!--
                  -->{% if pv.unit %}<!--
                    --> in {{ pv.unit }}<!--
                  -->{% endif %}<!--
                -->{% elsif pv.unit %}<!--
                  -->{{ pv.unit }}<!--
                -->{% elsif pv.type %}<!--
                  -->{{ pv.type }}<!--
                -->{% else %}<!--
                  -->Unknown<!--
                -->{% endif %}<!--
                -->{% if pv.optional %}&#x5D;{% else %}&gt;{% endif %}<!--
              -->{% else %}<!--
                -->&lt;<!--
                -->{% for pv in parm.values %}<!--
                  -->{{ pv.tag }}<!--
                  -->{% if forloop.last != true %}<!--
                    -->&#x7C;<!--
                  -->{% endif %}<!--
                -->{% endfor %}<!--
                -->&gt;<!--
              -->{% endif %}<!--
            -->{% endif %}<!--
            -->{% if parm.optional %}&#x5D;{% endif %}<!--
          --></span><!--
     -->{% endfor %}
      {% endif %}
    {% endif %}
  </code>
</div>
{% endif %}

{% if gcode.parameters %}
  {% assign list = ('' | split: '|') %}
  {% for parm in gcode.parameters %}
    {% if parm.tag %}
      {% assign list = list | push: parm %}
    {% endif %}
  {% endfor %}

  {% if list.size > 0 %}
    <div class="col-lg-12 row params">
      <h4>Parameters</h4>
      <div class="table-responsive">
        <table class="table">
          <tbody>
            {% assign list = (list | sort: 'tag') %}
            {% for parm in list %}
              <tr>
                <td class="arg"><code>
                  {% if parm.optional %}&#x5B;{% endif %}<!--
                  -->{{ parm.tag }}<!--
                  -->{% if parm.values.size > 0 %}<!--
                    -->{% if parm.values.size == 1 %}<!--
                      -->{% assign pv = parm.values[0] %}<!--
                      -->{% if pv.optional %}&#x5B;{% else %}&lt;{% endif %}<!--
                      -->{% if pv.tag %}<!--
                        -->{{ pv.tag }}<!--
                        -->{% if pv.unit %}<!--
                          --> in {{ pv.unit }}<!--
                        -->{% endif %}<!--
                      -->{% elsif pv.unit %}<!--
                        -->{{ pv.unit }}<!--
                      -->{% elsif pv.type %}<!--
                        -->{{ pv.type }}<!--
                      -->{% else %}<!--
                        -->Unknown<!--
                      -->{% endif %}<!--
                      -->{% if pv.optional %}&#x5D;{% else %}&gt;{% endif %}<!--
                    -->{% else %}<!--
                      -->&lt;<!--
                      -->{% for pv in parm.values %}<!--
                        -->{{ pv.tag }}<!--
                        -->{% if forloop.last != true %}<!--
                          -->&#x7C;<!--
                        -->{% endif %}<!--
                      -->{% endfor %}<!--
                      -->&gt;<!--
                    -->{% endif %}<!--
                  -->{% endif %}<!--
                  -->{% if parm.optional %}&#x5D;{% endif %}
                </code></td>
                <td>
                  {{ parm.description | markdownify }}
                  {% if parm.values.size > 0 %}
                    <ul class="param-desc-list">
                      {% for pv in parm.values %}
                        {% if pv.description %}
                          <li>
                            <code>{{ parm.tag }}{{ pv.tag }}</code>: {{ pv.description | markdownify }}
                          </li>
                        {% endif %}
                      {% endfor %}
                    </ul>
                  {% endif %}
                </td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  {% endif %}
{% endif %}

{% if gcode.images %}
<div class="col-lg-12 row gallery" id="gallery-{{ gcode.tag }}">
  <h3>Gallery</h3>
  {% for img in gcode.images %}
    {% assign cap = img.caption | markdownify %}
    {% assign ttl = img.title | markdownify | strip_html %}
    <h4>{{ ttl }}</h4>
    {{ cap }}
    <img src="{{ img.path | prepend: '/assets/images/gcode/' }}" alt="{{ ttl | xml_escape }}" title="{{ ttl | xml_escape }}" />
  {% endfor %}
</div>
{% endif %}

{% if gcode.videos %}
<div class="col-lg-12 row videos" id="videos-{{ gcode.tag }}">
  <h3>Related Media</h3>
  {% for videoid in gcode.videos %}
    <iframe class="youtube" width="300" height="225" src="https://www.youtube.com/embed/{{ videoid }}"></iframe>
  {% endfor %}
</div>
{% endif %}

{% if gcode.examples %}
  {% assign ex = gcode.examples %}
  {% assign plural = "s" %}
{% else %}
  {% if gcode.example %}
    {% assign ex = gcode.example %}
    {% assign plural = "" %}
  {% else %}
    {% assign ex = [] %}
  {% endif %}
{% endif %}

{% if ex %}
  <div class="col-lg-12 row examples">
    <h3>Example{{ plural }}</h3>
    {% for example in ex %}
      {% if example.pre %}
        {% for line in example.pre %}
          {{ line | markdownify }}
        {% endfor %}
      {% endif %}
      {% highlight gcode %}{% for line in example.code %}{{ line }}
{% endfor %}{% endhighlight %}
      {% if example.post %}
        <div class="post">
          {% for line in example.post %}
            {{ line | markdownify }}
          {% endfor %}
        </div>
      {% endif %}
    {% endfor %}
  </div>
{% endif %}
